<?php
class WeixinController extends Action
{
    static $service;
    public function valid ()
    {}
    public function v ()
    {
        $wechatObj = new WeixinService();
        $rs = $wechatObj->getComment();
        $this->view()->assign('maxid', $rs[0]['id']);
        $this->view()->assign('rs', $rs);
        $this->view()->display('file:app/weixin.tpl');
    }
    public function config ()
    {
        $welcome = self::getService()->getConfigById(2);
        $button = self::getService()->getConfigById(3);
        $server = self::getService()->getConfigById(4);
        $this->view()->assign('server', $server);
        $this->view()->assign('welcome', $welcome);
        $this->view()->assign('button', $button);
        $this->view()->display('file:app/config.tpl');
    }
    public function saveConfig ()
    {
        $rs = self::getService()->saveConfigById($_POST['value'], $_POST['id']);
        $this->sendNotice($rs['message'], null, $rs['status']);
    }
    public function saveButton ()
    {
        $rs = self::getService()->saveButton($_POST['value']);
        $this->sendNotice($rs['message'], null, $rs['status']);
    }
    //拉取新的聊天记录
    public function pull ()
    {
        $wechatObj = new WeixinService();
        $rs = $wechatObj->getCommentMaxId($_POST['maxid']);
        $this->sendNotice(null, $rs['data'], $rs['status']);
    }
    public function reply ()
    {
        $wechatObj = new WeixinService();
        $rs = $wechatObj->reply($_POST['touser'], $_POST['msg'], $_POST['id']);
        $this->sendNotice($rs['message'], null, $rs['status']);
    }
    public function listing ()
    {
        $wechatObj = new WeixinService();
        $rs = $wechatObj->getCommentPage($_GET['p']);
        $this->view()->assign('rs', $rs['user']);
        $this->view()->assign('num', $rs['page']);
        $this->view()->display('file:app/list.tpl');
    }
    public static function getService ()
    {
        if (self::$service == null) {
            self::$service = new WeixinService();
        }
        return self::$service;
    }
}